//
//  SSStatusHeaderView.swift
//  MyMicroBlog
//
//  Created by stevenSu on 15/8/1.
//  Copyright © 2015年 stevenSu. All rights reserved.
//

import UIKit

private let nameLabelFontSize: CGFloat = 14
private let createLabelFontSize: CGFloat = 9
private let separatorViewBackgroundColor = UIColor(white: 0.95, alpha: 1.0)
private let separatorViewHeight: CGFloat = 10
private let iconViewSize: CGFloat = 35
private let iconViewOffSet: CGFloat = 10
private let nameLabelXOffset: CGFloat = 15
private let elementOffSet: CGFloat = 5
private let verifyViewOffset = CGPoint(x: 8, y: 8)
class SSStatusHeaderView: UIView {
    var status: SSStatus? {
        didSet {
            if status != nil {
                iconView.sd_setImageWithURL(status!.user?.avatarURL)
            }

            nameLabel.text = status?.user?.name
            let time = status?.created_at ?? ""
            createLabel.text = NSDate.inputDate(time)?.dateDescription
            sourceLabel.text = status?.source ?? ""
            verifyView.image = status?.user?.verifiedImage
            mbrankView.image = status?.user?.mbrankImage
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private lazy var iconView: UIImageView = UIImageView(image: UIImage())
    private lazy var nameLabel: UILabel = UILabel(fontColor: UIColor.darkGrayColor(), fontSize: nameLabelFontSize)
    private lazy var createLabel: UILabel = UILabel(fontColor: UIColor.orangeColor(), fontSize: createLabelFontSize)
    private lazy var sourceLabel: UILabel = UILabel(fontColor: UIColor.lightGrayColor(), fontSize: createLabelFontSize)
    private lazy var verifyView: UIImageView = UIImageView()
    private lazy var mbrankView: UIImageView = UIImageView()
    
    private func setupUI() {
        let separatorView = UIView()
        separatorView.backgroundColor = separatorViewBackgroundColor
        addSubview(separatorView)
        separatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: separatorViewHeight))
        
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(createLabel)
        addSubview(sourceLabel)
        addSubview(verifyView)
        addSubview(mbrankView)
        
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: separatorView, size: CGSize(width: iconViewSize, height: iconViewSize), offset: CGPoint(x: iconViewOffSet, y: iconViewOffSet))
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: nameLabelXOffset, y: 0))
        createLabel.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: nameLabel, size: nil, offset: CGPoint(x: 0, y: elementOffSet))
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: createLabel, size: nil, offset: CGPoint(x: elementOffSet, y: 0))
        verifyView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: verifyViewOffset)
        mbrankView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: nil, offset: CGPoint(x: elementOffSet, y: 0))
        
    }
}
